$(function(){
	checkLogin();
	var repliedCustNo = getUrlParam('repliedCustNo');
	var postId = getUrlParam('postId');
	var postType = getUrlParam('postType');
	
	var custName = decodeURIComponent(getUrlParam('custName'));
	if(repliedCustNo){
		$('.comment-txt').attr('placeholder','回复 '+custName+':')
	}
	$('.comment-txt').on('input propertychange',function(){
		if($.trim($(this).val())){

			$('.ops a').addClass('postit')
		}else{
			$('.ops a').removeClass('postit')
		}
	})
	$('.ops a').click(function(){
		if($(this).hasClass('postit')){
			postComment(postId,postType,$.trim($('.comment-txt').val()),repliedCustNo);//增加参数
		}
	});
	$('.backBtn').attr('href','javascript:void(0)')
	$('.backBtn').click(function(e){
		var pathname ='';
		switch (postType) {
			case '0':
				pathname = '/duimen/detail/detail.html';
	        case '1':
	            pathname = '/duimen/detail/detail-sign.html';
	            break;
	        case '2':
	            pathname = '/duimen/vote/vote.html';
	            break;
	        case '3':
	            pathname = '/duimen/detail/detail-sign.html';
	            break;
	    };
	    console.log(2);
		location.href=pathname+'?postType='+postType+'&postId='+postId;
		e.stopPropagation();
	})
})
var postComment = function(postId,postType,comment,repliedCustNo){
		
		$.ajax({
			url:baseurl+"/post/save/comment.do",
			type:'GET',
			dataType:'jsonp',
			data:{
				postId:postId,
				comment:comment,
				repliedCustNo:repliedCustNo
			}
		}).then(function(data){
			if(data.resultCode == 0){
				console.log('成功');
				var pathname ='';
				switch (postType) {
					case '0':
						pathname = '/duimen/detail/detail.html';
			        case '1':
			            pathname = '/duimen/detail/detail-sign.html';
			            break;
			        case '2':
			            pathname = '/duimen/vote/vote.html';
			            break;
			        case '3':
			            pathname = '/duimen/detail/detail-sign.html';
			            break;
			    };
				console.log(pathname);
				location.href=pathname+'?postType='+postType+'&postId='+postId;
			}else{
				console.log(data.resultMsg);
				AlertBox({
					msg:data.resultMsg,
					type:'mini'
				})
			}
		})
}
